package sz.szsmk.citizencard.ui.adapter;

import android.os.Bundle;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.databinding.QuestionItemBinding;
import sz.szsmk.citizencard.model.network.bean.response.QuestionRes;
import sz.szsmk.citizencard.ui.activity.QuestionActivity;
import sz.szsmk.citizencard.util.JumpUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Copyright (c)2018
 * author: zdh
 * created on: 2018/7/25 21:48
 * description:
 */
public class QuestionAdapter extends RecyclerView.Adapter<QuestionAdapter.QuestionHolder> {
    private ArrayList<String> mTitle = new ArrayList<>();
    private QuestionActivity mContext;

    private List<QuestionRes.InterlcutionListBean> mList = new ArrayList<>();

    public QuestionAdapter(QuestionActivity questionActivity) {
        mContext = questionActivity;
        mTitle.add("客服热线");
        mTitle.add("休闲年卡相关问题");
        mTitle.add("园林年卡相关问题");
        mTitle.add("省一卡通相关问题");
        mTitle.add("亲自娃娃卡相关问题");
    }

    @Override
    public int getItemViewType(int position) {
        return R.layout.question_item;
    }

    @Override
    public QuestionHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return QuestionHolder.creat(parent);
    }

    @Override
    public void onBindViewHolder(QuestionHolder holder, int position) {
        loadItemData(position, holder.binding);
    }

    private void loadItemData(final int position, QuestionItemBinding binding) {

        binding.questionTitle.setText(mList.get(position).getQustion());
        binding.questionRl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putString("qustion",mList.get(position).getQustion());
                bundle.putString("answer",mList.get(position).getAnswer());
                JumpUtils.jumptoNatvie(mContext,"questiondetail",0,bundle);
            }
        });
    }


    @Override
    public int getItemCount() {
        return null == mList ? 0 : mList.size();
    }

    public void setItemData(List<QuestionRes.InterlcutionListBean> interlcution_list) {
        mList = interlcution_list;
    }


    public static class QuestionHolder extends RecyclerView.ViewHolder {
        private QuestionItemBinding binding;

        public static QuestionHolder creat(ViewGroup parent) {
            QuestionItemBinding binding = QuestionItemBinding
                    .inflate(LayoutInflater.from(parent.getContext()), parent, false);
            return new QuestionHolder(binding);
        }


        public QuestionHolder(QuestionItemBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }

}
